package com.ruix.app.mapper;

import android.text.TextUtils;

import com.ruix.app.cache.CacheFactory;
import com.ruix.app.manager.UserManager;
import com.ruix.app.model.OssToken;

import org.json.JSONObject;

/**
 * Created by hadexs on 2017/4/22.
 */

public class OssTokenMapper implements ApiMapper<OssToken>{
    @Override
    public OssToken transform(JSONObject response) {
        OssToken token = null;
        JSONObject data = response.optJSONObject("data");
        if (data != null) {
            token = new OssToken().parse(data);
            if (token != null && !TextUtils.isEmpty(token.getSecurityToken())) {
                CacheFactory.cacheOssToken(UserManager.getCurrentUser().getID(), token);
            }

        }
        return token;
    }
}
